package kyssion.leetcode.num201_250;

public class code205_同构字符串 {

    public static void main(String[] args) {
        System.out.println(new code205_同构字符串().isIsomorphic(
                "ab", "aa"
        ));
    }

    public boolean isIsomorphic(String s, String t) {
        return ans(s, t);
    }

    public boolean ans(String s, String t) {
        if (t == null) {
            return s == null;
        }
        if (s == null) {
            return false;
        }

        char[] map = new char[256];
        char[] use = new char[256];
        for (int a = 0; a < s.length(); a++) {
            if(map[s.charAt(a)]==0){
                if(use[t.charAt(a)]!=0){
                    return false;
                }
                map[s.charAt(a)]= t.charAt(a);
                use[t.charAt(a)]=t.charAt(a);
            }else{
                if(map[s.charAt(a)]!=t.charAt(a)){
                    return false;
                }
            }
        }
        return true;
    }
}
